<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>4309：Maishroom & Mushroom</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">Maishroom & Mushroom</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">Maishroom & Mushroom</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                Maishroom & Mushroom                </h1>
                <p>时间限制：20s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：1024MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><div>Maishroom有一个蘑菇，我们不妨称它为蘑菇1。蘑菇上有n个room，这些room按1..n编号，并组成了一棵树，其中room 1是根。由于Maishroom长期没有修剪，蘑菇1的每个room 里都长满了杂草。</div>
<div>众所周知Maishroom非常喜欢蘑菇，于是它对这个蘑菇进行了一系列操作，包括复制、合并、修剪和询问。这些操作的具体说明如下：</div>
<div>操作<span class="Apple-tab-span" style="white-space:pre">	</span>格式<span class="Apple-tab-span" style="white-space:pre">	</span>说明</div>
<div>复制<span class="Apple-tab-span" style="white-space:pre">	</span>1 u<span class="Apple-tab-span" style="white-space:pre">	</span>Maishroom复制了蘑菇u，新的蘑菇编号为cnt+1。</div>
<div>合并<span class="Apple-tab-span" style="white-space:pre">	</span>2 u v<span class="Apple-tab-span" style="white-space:pre">	</span>Maishroom将蘑菇v合并到了蘑菇u上。当然，如果某个旧蘑菇的某个room有杂草，新的蘑菇u的对应room中也会有杂草。合并完后蘑菇v不会消失。</div>
<div>修剪1<span class="Apple-tab-span" style="white-space:pre">	</span>3 u v<span class="Apple-tab-span" style="white-space:pre">	</span>Maishroom除去了蘑菇u上以room x为根的子树上的杂草。</div>
<div>修剪2<span class="Apple-tab-span" style="white-space:pre">	</span>4 u v<span class="Apple-tab-span" style="white-space:pre">	</span>Maishroom几乎除去了蘑菇u上所有的杂草，除了以room x为根的子树上的那些。</div>
<div>修剪3<span class="Apple-tab-span" style="white-space:pre">	</span>5 u x y<span class="Apple-tab-span" style="white-space:pre">	</span>Maishroom除去了蘑菇u上room x到room y 路径上的杂草。</div>
<div>修剪4<span class="Apple-tab-span" style="white-space:pre">	</span>6 u x y<span class="Apple-tab-span" style="white-space:pre">	</span>Maishroom几乎除去了蘑菇u上所有的杂草，除了room x到room y路径上的那些。</div>
<div>修剪5<span class="Apple-tab-span" style="white-space:pre">	</span>7 u l r<span class="Apple-tab-span" style="white-space:pre">	</span>Maishroom除去了蘑菇u上编号在L到r之间（包括L,R）的room中的杂草。</div>
<div>修剪6<span class="Apple-tab-span" style="white-space:pre">	</span>8 u l r<span class="Apple-tab-span" style="white-space:pre">	</span>Maishroom几乎除去了蘑菇u上所有的杂草，除了编号在L到r之间（包括L,r）的room 中的那些。</div>
<div>询问<span class="Apple-tab-span" style="white-space:pre">	</span>9 u w<span class="Apple-tab-span" style="white-space:pre">	</span>Maishroom想知道清除蘑菇u上所有杂草所需的时间。Maishroom有一种工具来清除蘑菇上的杂草，每使用一次Maishroom可以选定一个蘑菇上编号的极差不超过w的一些room并清除它们中的杂草，使用一次消耗一个单位的时间。</div>
<div>注：表中的cnt表示该操作进行之前Maishroom拥有的蘑菇数。</div>
<div>现在有一份Maishroom的操作记录，你的任务是回答Maishroom的每个询问。</div>
<div></div>
<p></p></p><hr/><h3>输入格式</h3><p><div>第一行一个整数n，表示蘑菇上room的个数。</div>
<div>接下来n-1行，每行两个整数x,y，表示room x,y之间有一条边。</div>
<div>接下来一行一个整数q，表示Maishroom的操作次数。</div>
<div>接下来q行，每行表示Maishroom的一个操作。</div>
<p></p></p><hr/><h3>输出格式</h3><p><div>对于每个询问输出一行表示该询问的答案。</div>
<div></div>
<p></p></p><hr/><h3>样例输入</h3><pre>5
1 3
3 5
1 2
2 4
9
1 1
1 2
5 3 4 5
9 3 0
2 3 2
6 3 4 5
9 3 1
4 2 2
9 2 1
</pre><hr/><h3>样例输出</h3><pre>0
3
2
</pre><hr/><h3>提示</h3><p><p class="MsoNormal" style="text-align:justify;text-justify:inter-ideograph"><span lang="EN-US" style="font-size:10.5pt;line-height:115%;font-family:微软雅黑;
mso-bidi-font-family:微软雅黑">N&lt;=50000,Q&lt;=100000,W</span><span style="font-size:10.5pt;line-height:115%;font-family:微软雅黑;mso-bidi-font-family:
微软雅黑">在<span lang="EN-US">[0,200]</span>中随机<span lang="EN-US"><o:p></o:p></span></span></p>
<p></p></p><hr/><h3>题目来源</h3><p>没有写明来源</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=4309" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=4309" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>